package com.redstars.generate.controller;

import com.redstars.generate.page.PageResult;
import com.redstars.generate.result.Result;
import com.redstars.generate.vo.SysTableFieldVo;
import lombok.AllArgsConstructor;
import com.redstars.generate.service.SysTableFieldService;
import com.redstars.generate.query.SysTableFieldQuery;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
* 代码生成表字段
*
* @author zhouhx 
* @since 1.0.0 2022-10-05
*/
@RestController
@RequestMapping("gen/field")
@AllArgsConstructor
public class SysTableFieldController {
    private final SysTableFieldService sysTableFieldService;

    /* *
     *
     * @author zhuohx
     * @description 分页
     * @parms  [query]
     * @return com.redstars.generate.result.Result<com.redstars.generate.page.PageResult<com.redstars.generate.vo.SysTableFieldVo>>
     * @throws
     * @date 2022/10/5 15:53
     */
    @GetMapping("page")
    public Result<PageResult<SysTableFieldVo>> page(@Valid SysTableFieldQuery query){
        PageResult<SysTableFieldVo> page = sysTableFieldService.page(query);

        return Result.ok(page);
    }

    /* *
     *
     * @author zhuohx
     * @description 详情
     * @parms  [query]
     * @return com.redstars.generate.result.Result<com.redstars.generate.vo.SysTableFieldVo>
     * @throws
     * @date 2022/10/5 15:53
     */
    @GetMapping("detail")
    public Result<SysTableFieldVo> detail(SysTableFieldQuery query){
        SysTableFieldVo detail = sysTableFieldService.detail(query);

        return Result.ok(detail);
    }

    /* *
     *
     * @author zhuohx
     * @description 保存
     * @parms  [vo]
     * @return com.redstars.generate.result.Result<java.lang.String>
     * @throws
     * @date 2022/10/5 15:53
     */
    @PostMapping
    public Result<String> save(@RequestBody SysTableFieldVo vo){
        sysTableFieldService.save(vo);

        return Result.ok();
    }

    /* *
     *
     * @author zhuohx
     * @description 修改
     * @parms  [vo]
     * @return com.redstars.generate.result.Result<java.lang.String>
     * @throws
     * @date 2022/10/5 15:54
     */
    @PutMapping
    public Result<String> update(@RequestBody @Valid SysTableFieldVo vo){
        sysTableFieldService.update(vo);

        return Result.ok();
    }

    /* *
     *
     * @author zhuohx
     * @description 删除
     * @parms  [idList]
     * @return com.redstars.generate.result.Result<java.lang.String>
     * @throws
     * @date 2022/10/5 15:54
     */
    @DeleteMapping
    public Result<String> delete(@RequestBody List<Long> idList){
        sysTableFieldService.delete(idList);

        return Result.ok();
    }

    /* *
     *
     * @author zhuohx
     * @description 根据tableid查询表中字段
     * @parms  [tableId]
     * @return com.redstars.generate.result.Result<java.util.List<com.redstars.generate.vo.SysTableFieldVo>>
     * @throws
     * @date 2022/11/8 14:34
     */
    @GetMapping("getByTableId/{tableId}")
    public Result<List<SysTableFieldVo>> getByTableId(@PathVariable("tableId") Long tableId){
        List<SysTableFieldVo> fieldVos = sysTableFieldService.getByTableId(tableId);
        return Result.ok(fieldVos);
    }
}